﻿using BootstrapBlazor.Components;
using CodeMan.Application.Contracts.ClassGens;
using CodeMan.Application.ClassGens;
using CodeMan.ClassGens;
using System.Collections.Generic;
using System.Threading.Tasks;
using Volo.Abp.Application.Dtos;
using Volo.Abp.Application.Services;
using Volo.Abp.DependencyInjection;
using Volo.Abp.ObjectMapping;
using Microsoft.Extensions.Configuration;
using CodeManDesktopBlazor.BlazorComponents.Data;
using Volo.Abp.Data;

namespace CodeManDesktopBlazor
{
    public class HelloWorldService : ISingletonDependency
    {

        private readonly IDataService<ClassGenDTO> _codeManClassGenAppService;
        private readonly IClassGenAppService _ClassGenService;
        private readonly IClassAttributeAppService _ClassAttributeService;
        private readonly IOtherDBAppService _OtherDBAppService;
        private readonly IConnectionStringResolver _connectionStringResolver;
        private IObjectMapper ObjectMapper;
        public static IConfiguration Configuration { get; set; }

        public HelloWorldService(IDataService<ClassGenDTO> codeManClassGenAppService,
            IClassGenAppService classGenService, IObjectMapper objectMapper,
            IClassAttributeAppService classAttributeService,
            IOtherDBAppService otherDBAppService,
            IConnectionStringResolver connectionStringResolver,
            IConfiguration configuration
            )
        {
            _codeManClassGenAppService = codeManClassGenAppService;
            _ClassGenService = classGenService;
            _ClassAttributeService = classAttributeService;
            _OtherDBAppService = otherDBAppService;
            ObjectMapper = objectMapper;
            Configuration = configuration;
            _connectionStringResolver = connectionStringResolver;
        }
        public async Task Demotodo()
        { 

            //await _OtherDBAppService.GetAllTables();
        }

        public async Task<QueryData<ClassGenDTO>> DoItAsync()
        {
            QueryPageOptions option = new QueryPageOptions();
            //Get all users
            var users = await _codeManClassGenAppService.QueryAsync(option);

            return users;
        }
        public async Task<QueryData<ClassGenDTOCreateUpdate>> DoItAsync2(string name = "xlgwr")
        {
            ClassGenDTOCreateUpdate classGenDTO = new ClassGenDTOCreateUpdate() { Name = name };

            await _ClassGenService.AddAsync(classGenDTO);
            //Get all users
            var users = await _ClassGenService.QueryAsync(new QueryPageOptions());

            var dd = ((IDataService<ClassGenDTOCreateUpdate>)_ClassGenService).SaveAsync(classGenDTO, ItemChangedType.Update);

            return users;
        }
        public IDataService<ClassGenDTOCreateUpdate> GetDataService()
        {
            return ((IDataService<ClassGenDTOCreateUpdate>)_ClassGenService);
        }
        public IConnectionStringResolver GetconnectionStringResolver()
        {
            return _connectionStringResolver;
        }
        public IClassGenAppService GetClassGenAppService()
        {
            return _ClassGenService;
        }
        public IOtherDBAppService GetOtherDBAppService()
        {
            return _OtherDBAppService;
        }
        public IDataService<ClassAttributeDTO> GetDataDetailsMainService()
        {
            return ((IDataService<ClassAttributeDTO>)_ClassAttributeService);
        }
        public IDataDetailService<ClassAttributeDTO> GetDataDetailsService()
        {
            return ((IDataDetailService<ClassAttributeDTO>)_ClassAttributeService);
        }
        public IObjectMapper GetobjectMapper()
        {
            return ObjectMapper;
        }
        public string SayHello()
        {
            return "Hello world!";
        }
    }
}
